import { Alova, AlovaWinthoutCache } from '@/utils/http/alova/index';

interface NoiseRssi {
  freq: number;
  ant1Rssi: number;
  ant2Rssi: number;
}

export interface NodeInfo {
  ip: string;
  altitude: number;
  longitude: number;
  resourceRatio: number;
  latitude: number;
  id: number;
}

interface Device {
  status: number;
  version: string;
  type: string;
}

interface NodeRssi {
  ant1Rssi: number;
  ant2Rssi: number;
  id: number;
}

interface Delay {
  delay: number;
  id: number;
}

export interface StatusConfig {
  linkQuality: number[][];
  batteryLevel: number;
  nodeNumber: number;
  heterogeneousLinkNodes: any[]; // 可以根据实际数据类型替换'any'
  silenced: boolean;
  nodesRssi: NodeRssi[]; // 可以根据实际数据类型替换'any'
  ip: string;
  selfId: number;
  noiseRssi: NoiseRssi[];
  operatingFreq: number;
  date: string;
  dnsServer: string;
  temp: number;
  nwMask: string;
  transmissionDelay: Delay[]; // 可以根据实际数据类型替换'any'
  nodeInfos: NodeInfo[];
  devices: Device[];
  gateway: string;
  configUpdated: boolean;
  operatingCtrlFreqMask: string;
}

interface AddressTableItem {
  [key: string]: number;
}

export interface StatusAdvanced {
  unicastFwOverflow: number;
  operatingVersion: number;
  audioTotalAllocateSlotNumber: number;
  unicastAllocateSlotNumber: number;
  aaSubband1Snr0Avg: number;
  multicastResourceTotal: number;
  aaCrcErrCount: number;
  unicastTxOverflow: number;
  ethRxBytes: number;
  aaSubband1Snr0Max: number;
  aaSubband0CrcErrRatio1: string;
  aaSubband0CrcErrRatio0: string;
  aaSubband0CrcErrRatio2: string;
  aaSubband1Snr2Min: number;
  audioTotalRequestSlotNumber: number;
  nodeStatus: number;
  phyTxBytes: number;
  aaSubband0Snr1Max: number;
  aaSubband0Snr2Max: number;
  aaSubband0Snr1Avg: number;
  convergenceLinkNodes: any[]; // 可根据实际类型替换
  aaSlotOffsetAvg: number;
  aaSubband1Snr1Min: number;
  aaSubband1CrcErrRatio0: string;
  aaSubband1CrcErrRatio1: string;
  aaSubband1CrcErrRatio2: string;
  unicastResourceTotal: number;
  arqRetransmit: number;
  aaSubband0Snr0Max: number;
  addressTable: AddressTableItem[];
  aaSubband0Snr0Min: number;
  aaSubband0CrcErrCount1: number;
  aaSubband0CrcErrCount0: number;
  aaSubband0CrcErrCount2: number;
  multicastTotalUsedSlotNumber: number;
  multicastRequestSlotNumber: number;
  freqSyncAdjust: number;
  aaSubband1Snr1Max: number;
  unicastUsedSlotNumber: number;
  aaSubband1CaptureCount0: number;
  aaSubband1CaptureCount1: number;
  aaSubband1CaptureCount2: number;
  aaSubband0Snr0Avg: number;
  multicastResourceDelta: number;
  unicastTotalAllocateSlotNumber: number;
  multicastBufferStatus: number;
  audioResourceTotal: number;
  multicastAllocateSlotNumber: number;
  unicastRequestSlotNumber: number;
  aaFreqOffsetMax: number;
  unicastResourceDelta: number;
  aaFreqOffsetMin: number;
  aaCaptureCount: number;
  aaSlotOffsetMin: number;
  aaSubband1Snr1Avg: number;
  unicastTotalRequestSlotNumber: number;
  aaSubband1Snr2Avg: number;
  unicastTotalUsedSlotNumber: number;
  multicastUsedSlotNumber: number;
  hhn: number;
  audioResourceDelta: number;
  aaSubband0Snr2Avg: number;
  rxStat: any[]; // 可根据实际类型替换
  netOverflow: number;
  aaSubband1CrcErrCount0: number;
  aaSubband1CrcErrCount1: number;
  aaSubband1CrcErrCount2: number;
  multicastTotalRequestSlotNumber: number;
  aaSubband0CaptureCount2: number;
  aaSubband0CaptureCount1: number;
  aaSubband0CaptureCount0: number;
  audioTotalUsedSlotNumber: number;
  aaSubband0Snr1Min: number;
  freqSyncAdjustDelta: number;
  aaSubband1Snr0Min: number;
  unicastRxLost: number;
  phyVersion: string;
  aaSubband0Snr2Min: number;
  audioRequestSlotNumber: number;
  audioRxLost: number;
  aaSlotOffsetMax: number;
  bbn: number;
  audioUsedSlotNumber: number;
  phyRxBytes: number;
  freqOffset: any[]; // 可根据实际类型替换
  multicastTotalAllocateSlotNumber: number;
  aaFreqOffsetAvg: number;
  aaCrcErrRatio: string;
  audioTxOverflow: number;
  mpVersion: string;
  audioAllocateSlotNumber: number;
  aaSubband1Snr2Max: number;
  calibrated: number;
  ethRxPackets: number;
}

export interface StatusAll {
  status: StatusConfig;
  statusAdvanced: StatusAdvanced;
}

export interface RssiStatus {
  rssi: number[][];
}

//获取status参数
export function getStatusConfig() {
  return AlovaWinthoutCache.Get<StatusConfig>('/status', {
    meta: {
      isReturnNativeResponse: true, // 关键配置, 返回原生响应头
    },
  });
}

// 通过ip获取status参数
export function getStatusByIp(ip: string) {
  return AlovaWinthoutCache.Get<StatusConfig>(`http://${ip}/status`, {
    meta: {
      isReturnNativeResponse: true, // 关键配置, 返回原生响应头
    },
  });
}

//获取rssi
export function getRssiStatus() {
  return AlovaWinthoutCache.Get<RssiStatus>('/spectrum', {
    meta: {
      isReturnNativeResponse: true, // 关键配置, 返回原生响应头
    },
  });
}

// 通过ip获取rssi
export function getRssiStatusByIp(ip: string) {
  return AlovaWinthoutCache.Get<RssiStatus>(`http://${ip}/spectrum`, {
    meta: {
      isReturnNativeResponse: true, // 关键配置, 返回原生响应头
    },
  });
}

// 获取statusadvance
export function getStatusAdvanced() {
  return AlovaWinthoutCache.Get<StatusAdvanced>('/statusadvanced', {
    meta: {
      isReturnNativeResponse: true, // 关键配置, 返回原生响应头
    },
  });
}

// 通过ip获取statusadvance
export function getStatusAdvancedByIp(ip: string) {
  return AlovaWinthoutCache.Get<StatusAdvanced>(`http://${ip}/statusadvanced`, {
    meta: {
      isReturnNativeResponse: true, // 关键配置, 返回原生响应头
    },
  });
}
